﻿// 界面自适应
(function() {

//var oldPos, oldTop, oldTime, area = $(".area");
//var timer, duration = 500, tick = 30;

if (!window.WebApi) {

    function resize() {
        $("body").css({
            paddingTop : $(".header").height("padding margin border"),
            paddingBottom : $(".footer").height("padding margin border")
        });
    }
    window.autoResize = resize;

    resize();

    //$(window).on("resize", resize);
}


/*var oldPos, area = $(".area");

area.on("touchstart", function(e) {
    e.preventDefault();
    oldPos = e.targetTouches[0].clientY;
}).on("touchmove", function(e) {
    if (oldPos != null) {
        var newPos = e.targetTouches[0].clientY;
        this.scrollTop -= newPos - oldPos;
        
        oldPos = newPos;
    }
}).on("touchend", function() {
    oldPos = null;
});*/

//function swing(p){
//	return -( Math.cos( p*Math.PI )/2 ) + 0.5
//}

//area.on("touchstart", function(e) {
//    e.preventDefault();
//	clearInterval(timer);
//	
//    oldPos = e.targetTouches ? e.targetTouches[0].clientY : e.clientY;
//	oldTime = e.timeStamp;
//}).on("touchmove", function(e) {
//    if (oldPos != null && e.timeStamp - oldTime > 20) {
//		var newPos = e.targetTouches ? e.targetTouches[0].clientY : e.clientY;

//        oldTop = this.scrollTop;
//		this.scrollTop -= newPos - oldPos;
//        this.hasMove = true;
//		
//        oldPos = newPos;
//		oldTime = e.timeStamp;
//    }
//}).on("touchend,mouseup,mouseout", function(e) {
//	var self = this;
//	
//	if(!self.hasMove) {
//		delete self.hasMove;
//		var target = e.target;
//		if(target.nodeType == 3)	target = target.parentNode;
//			
//		var event = document.createEvent("MouseEvents");
//		event.initEvent('click', true, true);
//		
//		target.dispatchEvent(event);
//		return false;
//	}
//	
//	var start = new Date(),	distance = duration / 20 * (this.scrollTop - oldTop) / (e.timeStamp - oldTime);
//	console && console.info(self.distance);
//	
//	timer = setInterval(function(){
//		var now = new Date();
//		var percent = (now - start) / duration;
//		if(percent >= 1) {
//			clearInterval(timer);
//		} else {
//			self.scrollTop = oldTop + swing(percent) * distance;
//		}
//	}, tick);
//});

})();
